package coop.bancocredicoop.proyectos.gd.fileListing;

import java.io.File;
import java.io.IOException;

import coop.bancocredicoop.proyectos.gd.fileListing.DirectoryItem;

public class FolderItem extends DirectoryItem {
	
	private DocumentBrowser browser;
	private File folder;
	
	public FolderItem(File folder, DocumentBrowser browser) throws IOException {
		if (!folder.isDirectory()) {
			throw new IllegalArgumentException("The file is not a directory: " + folder.getCanonicalPath());
		}
		this.folder = folder;
		this.browser = browser;
	}

	public String getName() {
		return folder.getName();
	}

	public boolean getIsDirectory() {
		return true;
	}

	public boolean getIsDocument() {
		return false;
	}
	
	public Integer getAmountOfDocuments() throws IOException {
		return browser.countDocuments(0, folder);
	}

	@Override
	public String getRelativePath() throws IOException, InvalidFolderException {
		return browser.getRelativePath(folder);
	}
	
	public boolean getIsRootDirectory() throws IOException {
		return browser.isRootDirectory(folder.getCanonicalPath());
	}
	
	public String getParentDirectory() throws InvalidFolderException, IOException {
		return browser.getParentDirectory(folder);
	}
	
}
